from django.db import models

# Create your models here.
from django.db import models


class Admin(models.Model):
    admin_id = models.CharField(max_length=20, primary_key=True)
    admin_pass = models.CharField(max_length=255)
    register_time = models.DateTimeField(auto_now_add=True)
    last_operation_time = models.DateTimeField(auto_now=True)
    responsible_scenic_id = models.CharField(max_length=60, blank=True, null=True)
    submitted_tickets = models.IntegerField(default=0)
    flag = models.IntegerField(default=1)  # 1 表示管理员


class Submitter(models.Model):
    submitter_id = models.CharField(max_length=20, primary_key=True)
    submitter_pass = models.CharField(max_length=255)
    register_time = models.DateTimeField(auto_now_add=True)
    last_operation_time = models.DateTimeField(auto_now=True)
    submitted_tickets = models.IntegerField(default=0)
    flag = models.IntegerField(default=0)  # 0 表示提交者
# from django.utils import timezone
# from .models import Submitter
#
# submitters = [
#     Submitter(
#         submitter_id=f'S{str(i).zfill(4)}',
#         submitter_pass=f'niuma{i:02}',
#         register_time=timezone.now(),
#         last_operation_time=timezone.now(),
#         submitted_tickets=0
#     )
#     for i in range(1, 21)  # S0001 to S0020 and niuma01 to niuma20
# ]
#
# Submitter.objects.bulk_create(submitters)


class DataChange(models.Model):
    change_id = models.AutoField(primary_key=True)
    qa = models.ForeignKey('QaPair', on_delete=models.CASCADE, db_column='qa_id', blank=True, null=True)
    current_status = models.CharField(max_length=20, default='on')
    modification_type = models.CharField(max_length=20, blank=True, null=True)
    original_question = models.TextField(blank=True, null=True)  # 修改为 TextField
    original_answer = models.TextField(blank=True, null=True)  # 修改为 TextField
    updated_question = models.TextField(blank=True, null=True)  # 修改为 TextField
    updated_answer = models.TextField(blank=True, null=True)  # 修改为 TextField
    change_time = models.DateTimeField(auto_now_add=True)
    modified_by = models.CharField(max_length=6, blank=True, null=True)
    ticket = models.ForeignKey('DataTicket', on_delete=models.CASCADE, db_column='ticket_id', blank=True, null=True)


class DataTicket(models.Model):
    STATUS_CHOICES = (
        ('待处理', '待处理'),
        ('已处理', '已处理'),
        ('驳回', '驳回'),
    )
    ticket_id = models.AutoField(primary_key=True)
    ticket_type = models.CharField(max_length=300)
    question = models.TextField()  # 修改为 TextField
    answer = models.TextField()  # 修改为 TextField
    submitter = models.ForeignKey(Submitter, on_delete=models.CASCADE, db_column='submitter_id', blank=True, null=True)
    submit_time = models.DateTimeField(auto_now_add=True)
    submit_count = models.IntegerField(default=0)
    assigned_admin = models.ForeignKey(Admin, on_delete=models.CASCADE, db_column='assigned_admin', blank=True,
                                       null=True)
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='待处理')
    flag=models.IntegerField(default=0)


class QaPair(models.Model):
    qa_id = models.AutoField(primary_key=True)
    jq = models.ForeignKey('ScenicSpot', on_delete=models.CASCADE, db_column='jq_id', blank=True, null=True)
    question = models.CharField(max_length=100)
    answer = models.TextField(blank=True, null=True)  # 修改为 TextField
    last_operation_time = models.DateTimeField(auto_now=True)


class ScenicSpot(models.Model):
    jq_id = models.CharField(max_length=60, primary_key=True)
    jq_name = models.CharField(max_length=50)
    jq_city = models.CharField(max_length=20)
    jq_address = models.TextField(null=True)  # 修改为TextField
    jq_rating = models.CharField(max_length=50)
    jq_type = models.CharField(max_length=20)
    qa_count = models.IntegerField(default=0)
    responsible_admin = models.ForeignKey(Admin, on_delete=models.CASCADE, db_column='responsible_admin', blank=True, null=True)

class TouristAttraction(models.Model):
    jq_name = models.ForeignKey(ScenicSpot, on_delete=models.CASCADE, db_column='jq_name')
    jq_intro = models.TextField()
    jq_what = models.TextField()
    jq_culture = models.TextField()
    jq_around = models.TextField()
    jq_vehicle = models.TextField()
    jq_address = models.TextField()
    jq_restaurant = models.TextField()
    jq_food = models.TextField()
    contents = models.TextField()
    class Meta:
        db_table = 'tourist_attraction'